<?php
namespace app\model;

use think\Model;
use Firebase\JWT\ExpiredException;
use Firebase\JWT\JWT as JWTUtil;

class Article extends Model
{
    //Token密钥设置为全局变量
    protected $jwt_secret_key = '123MeJump@';
    //过期时间1天
    protected $expire_time= 60*60*24;

    //生成token
    public function createToten($user=[],$exptime=0)
    {
        $key = md5($this->jwt_secret_key); //jwt的签发密钥，验证token的时候需要用到
        $time = time(); //签发时间
        $expire = $time + $exptime; //过期时间
        $token = array(
            $user,
            "iss" => "MeJump.cn",//签发组织
            "aud" => "vxinhao", //签发作者
            "iat" => $time,
            "nbf" => $time,
            "exp" => $expire
        );
        $jwt = JWTUtil::encode($token, $key);
        return $jwt;
    }
}

